package com.example.module_home.testmvi

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.example.module_home.R
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

class MviActivity : AppCompatActivity() {
    private val viewModel by viewModels<VideoTypeViewModel>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_mvi)
        lifecycleScope.launch {
            //start活跃状态订阅流信息
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                viewModel.intentChannel.send(VideoTypeIntent.GetSimpleType)
            }
        }

        lifecycleScope.launch {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                viewModel.getSimpleTypeState.collect{
                    when(it){
                        is VideoTypeState.GetSimpleTypeSuccess->{
                            Log.d("mvi", "数据加载成功: ${it.data}")
                        }
                        is VideoTypeState.GetMutilTypeSuccess->{

                        }
                        is VideoTypeState.GetMutilTypeByPidSuccess -> {

                        }
                        is VideoTypeState.Loading->{
                            Log.d("mvi", "数据加载中: ")

                        }
                        is VideoTypeState.Error->{
                            Log.d("mvi", "数据加载失败: ${it.msg}")
                        }
                        is VideoTypeState.Empty->{
                            Log.d("mvi", "空数据:")
                        }

                    }
                }
            }
        }


    }
}